package com.zelin.manager.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.zelin.manager.entity.SpecificationEntityVo;
import com.zelin.manager.group.Specification;
import com.zelin.manager.service.SpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zelin.manager.entity.SpecificationEntity;
import com.zelin.common.utils.PageUtils;
import com.zelin.common.utils.R;



/**
 * 
 *
 * @author LZB
 * @email 2668816865@gmail.com
 * @date 2021-10-26 10:21:00
 */
@RestController
@RequestMapping("manager/specification")
public class SpecificationController {
    @Autowired
    private SpecificationService specificationService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = specificationService.queryPage(params);

        return R.ok().put("page", page);
    }

    @GetMapping("/findAll")
    public  R findAll(){
        //获取规格规格参数
        List<SpecificationEntity> list = specificationService.list();
        List<SpecificationEntityVo> collect = list.stream().map(m -> {
            SpecificationEntityVo vo = new SpecificationEntityVo(m.getId(), m.getSpecName());
            return vo;
        }).collect(Collectors.toList());
        System.out.println(collect);
        return R.ok().put("list",collect);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		Specification specification = specificationService.findById(id);
        return R.ok().put("specification", specification);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody Specification specification){
		specificationService.insert(specification);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody Specification specification){
		specificationService.update(specification);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		specificationService.delete(Arrays.asList(ids));

        return R.ok();
    }

}
